package com.css.dzj.dzjfxyj.modules.reply.controller;

import com.css.aq.server.service.BaseService;
import com.css.dzj.dzjfxyj.common.util.R;
import com.css.dzj.dzjfxyj.modules.acquier.entity.JgFxyjWarningSignalEntity;
import com.css.dzj.dzjfxyj.modules.reply.entitiy.JgFxyjFeedbackEntity;
import com.css.dzj.dzjfxyj.modules.reply.service.replyService;
import com.css.dzj.dzjfxyj.modules.reply.vo.ReplyVo.ReplyVo;
import com.querydsl.core.QueryResults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping(value = "/reply")
public class replyController {
    @Autowired
    private replyService replyService;
    @Autowired
    BaseService baseService;
    /**
     * 查看所有待回复信息
     * @return
     */
    @GetMapping(value = "/getAllReply")
    public R getAllReply(@RequestParam(required = false) Integer pageNo,
                         @RequestParam(required = false) Integer pageSize,
                         HttpServletRequest request){
        PageRequest pageRequest = PageRequest.of(pageNo-1, pageSize);
        QueryResults results = replyService.getAllReply(pageRequest);
        baseService.logSuccess(3,"查询待回复成功","2");
        return R.ok().put("data", results);
    }

    /**
     * 查看详情回复页面VO
     * @return
     */
    @GetMapping(value = "/getOne")
    public R getOne(String id){
        ReplyVo replyVo = replyService.queryOne(id);
        baseService.logSuccess(3,"查询回复成功","2");
        return R.ok().put("data",replyVo);
    }
    /**
     * 新增回复信息
     */
    @PostMapping(value = "/addForce")
    public R addForce(@RequestBody ReplyVo vo, HttpServletRequest request){
        String msg = replyService.addReply(vo,request);
        baseService.logSuccess(3,"新增回复成功","2");
        return R.ok();
    }
    /**
     * 条件查询
     */
    @GetMapping("/getPage")
    public R getPage(@RequestParam(name = "pageSize" ,required = false)Integer pageSize,
                     @RequestParam(name = "pageNo" ,required = false)Integer pageNo,
                     @RequestParam(name = "fxyjDomainId" ,required = false)String fxyjDomainId,
                     @RequestParam(name = "fxyjTitle" ,required = false)String fxyjTitle,
                     @RequestParam(name = "fxyjLevel" ,required = false)String fxyjLevel,
                     @RequestParam(name = "fxyjObjectName" ,required = false)String fxyjObjectName,
                     @RequestParam(name = "startTime" ,required = false)String startTime,
                     @RequestParam(name = "endTime" ,required = false)String endTime,
                     @RequestParam(name = "startTime1" ,required = false)String startTime1,
                     @RequestParam(name = "endTime1" ,required = false)String endTime1){

        PageRequest pageRequest = PageRequest.of(pageNo-1,pageSize);
        QueryResults<JgFxyjWarningSignalEntity> page=replyService.getPage(pageRequest,fxyjDomainId,fxyjTitle,fxyjLevel,
                fxyjObjectName,startTime,endTime,startTime1,endTime1);
        baseService.logSuccess(3,"查询待回复成功","2");
        return R.ok().put("data",page);
    }
    /**
     * 修改回复信息状态
     */
    @PostMapping(value = "/updForce")
    public R updForce(@RequestBody JgFxyjFeedbackEntity jgFxyjFeedbackEntity){
        //String msg = replyService.addReply(jgFxyjFeedbackEntity);
        return R.ok();
}

    /**
     * 点击回复按钮时回显数据
     * @param id
     * @return
     */
    @PostMapping("/queryAcquire")
    public R queryAcquire(String id,String from, HttpServletRequest request){
        ReplyVo replyVo = replyService.queryAcquire(id,from,request);
        baseService.logSuccess(3,"查询回复回显成功","2");
        return R.ok().put("data",replyVo);
    }

    /**
     *通过主表ID获取所有回复信息
     * @param id
     * @return
     */
    @GetMapping("/queryList")
    public R queryList(String id){
        List<JgFxyjFeedbackEntity> list = replyService.queryList(id);
        baseService.logSuccess(3,"查询所有回复成功","2");
        return R.ok().put("data",list);
    }

}
